package com.clickpaas.governmentcloud.service.portalservice.impl;

import com.alibaba.fastjson.JSONObject;
import com.bizcloud.ipaas.tb4093760b8224c4fbcff37d3fa266753.d20210207141638.codegen.*;
import com.bizcloud.ipaas.tb4093760b8224c4fbcff37d3fa266753.d20210207141638.model.*;
import com.bizcloud.ipaas.tb4093760b8224c4fbcff37d3fa266753.d20210127152100.codegen.*;
import com.bizcloud.ipaas.tb4093760b8224c4fbcff37d3fa266753.d20210127152100.model.*;
import com.clickpaas.governmentcloud.common.Finals;
import com.clickpaas.governmentcloud.config.ApiInit;
import com.clickpaas.governmentcloud.entity.portalentity.rep.*;
import com.clickpaas.governmentcloud.entity.portalentity.rep.MenusRep.PolicyApplicationDemonstration;
import com.clickpaas.governmentcloud.entity.portalentity.req.MenusReq;
import com.clickpaas.governmentcloud.service.portalservice.PortalService;
import com.clickpaas.governmentcloud.utils.portalutils.JsonUtils;
import com.google.common.collect.Maps;
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.JsonNode;
import com.mashape.unirest.http.Unirest;
import com.mashape.unirest.http.exceptions.UnirestException;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpStatus;
import org.json.JSONArray;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.stream.Collectors;

/**
 * @author 方延杰
 * @version 1.0
 * @since 2020/11/10 6:39 下午
 */
@Service
public class PortalServiceImpl implements PortalService {

    public static final TPolicyDataCenterDTOPageInfo T_POLICY_DATA_CENTER_DTO_PAGE_INFO = new TPolicyDataCenterDTOPageInfo();
    @Resource
    TpolicyapplicationdemonstrationApi tpolicyapplicationdemonstrationApi;

    @Resource
    TlatestpolicyApi tlatestpolicyApi;

    @Resource
    TindustryApi tindustryApi;

    @Resource
    TsubdomainApi tsubdomainApi;

    @Resource
    TintroductionApi tintroductionApi;

    @Resource
    TpolicydatacenterApi tpolicydatacenterApi;

    @Resource
    ThorizontalaxisApi thorizontalaxisApi;

    @Override
    public ResponseResult<MenusRep> menus(MenusReq menusReq) {
        Integer page = menusReq.getPage();
        Integer size = menusReq.getSize();
        String name = menusReq.getName();
        String competentDepartment = menusReq.getCompetentDepartment();
        String applicationStatus = menusReq.getApplicationStatus();

        List<TPolicyApplicationDemonstrationDTO> apps = new ArrayList<>();
        List<TPolicyApplicationDemonstrationDTOPageInfoResponse> datas = apps();
        for (TPolicyApplicationDemonstrationDTOPageInfoResponse data : datas){
            TPolicyApplicationDemonstrationDTO tempData = new TPolicyApplicationDemonstrationDTO();
            BeanUtils.copyProperties(data,tempData);
            apps.add(tempData);
        }

        List<TPolicyApplicationDemonstrationDTO> result = new ArrayList<>();

        if (apps.size() > 0) {
            List<TPolicyApplicationDemonstrationDTO> applicationStatusNulls = new ArrayList<>();

            Map<String, List<TPolicyApplicationDemonstrationDTO>> groupingByApplicationStatusCollect = apps
                    .stream()
                    .filter(app -> {
                        String status = app.getApplicationStatus();
                        if (status != null) {
                            return true;
                        }
                        applicationStatusNulls.add(app);
                        return false;
                    })
                    .filter(app -> {
                        String name1 = app.getName();
                        String competentDepartment1 = app.getCompetentDepartment();
                        String applicationStatus1 = app.getApplicationStatus();

                        //只模糊'名称'
                        if (StringUtils.isNotEmpty(name) && StringUtils.isEmpty(competentDepartment) && StringUtils.isEmpty(applicationStatus) && StringUtils.isNotEmpty(name1)) {
                            return name1.contains(name);
                        } else
                            //只模糊'主管名称'
                            if (StringUtils.isEmpty(name) && StringUtils.isNotEmpty(competentDepartment) && StringUtils.isEmpty(applicationStatus) && StringUtils.isNotEmpty(competentDepartment1)) {
                                return competentDepartment.contains(competentDepartment1);
                            } else
                                //只模糊'申报状态'
                                if (StringUtils.isEmpty(name) && StringUtils.isEmpty(competentDepartment) && StringUtils.isNotEmpty(applicationStatus) && StringUtils.isNotEmpty(applicationStatus1)) {
                                    return applicationStatus.contains(applicationStatus1);
                                } else
                                    //模糊'名称''主管名称'
                                    if (StringUtils.isNotEmpty(name) && StringUtils.isNotEmpty(competentDepartment) && StringUtils.isEmpty(applicationStatus) && StringUtils.isNotEmpty(name1) && StringUtils.isEmpty(competentDepartment1)) {
                                        return name1.contains(name) && competentDepartment.contains(competentDepartment1);
                                    } else
                                        //模糊'名称''申报状态'
                                        if (StringUtils.isNotEmpty(name) && StringUtils.isEmpty(competentDepartment) && StringUtils.isNotEmpty(applicationStatus) && StringUtils.isNotEmpty(name1) && StringUtils.isEmpty(applicationStatus1)) {
                                            return name1.contains(name) && applicationStatus.contains(applicationStatus1);
                                        } else
                                            //模糊'主管名称''申报状态'
                                            if (StringUtils.isEmpty(name) && StringUtils.isNotEmpty(competentDepartment) && StringUtils.isNotEmpty(applicationStatus) && StringUtils.isNotEmpty(competentDepartment1) && StringUtils.isNotEmpty(applicationStatus1)) {
                                                return competentDepartment.contains(competentDepartment1) && applicationStatus.contains(applicationStatus1);
                                            } else
                                                //模糊'名称''主管名称''申报状态'
                                                if (StringUtils.isNotEmpty(name) && StringUtils.isNotEmpty(competentDepartment) && StringUtils.isNotEmpty(applicationStatus) && StringUtils.isNotEmpty(name1) && StringUtils.isNotEmpty(competentDepartment1) && StringUtils.isNotEmpty(applicationStatus1)) {
                                                    return name1.contains(name) && competentDepartment.contains(competentDepartment1) && applicationStatus.contains(applicationStatus1);
                                                } else {
                                                    return true;
                                                }
                    }).collect(Collectors.groupingBy(TPolicyApplicationDemonstrationDTO::getApplicationStatus));
            if (!CollectionUtils.isEmpty(groupingByApplicationStatusCollect)) {
                String applicationStatus1 = "申报中";
                String applicationStatus2 = "非申报时间";

                groupingByApplicationStatusCollect.forEach((k, v) -> {
                    if (applicationStatus1.equals(k)) {
                        v.sort(Comparator.comparing(TPolicyApplicationDemonstrationDTO::getDays));
                    }
                    if (applicationStatus2.equals(k)) {
                        v.sort((s1, s2) -> {
                            String deadline1 = s1.getDeadline();
                            String deadline2 = s2.getDeadline();
                            if (StringUtils.isNotEmpty(deadline1) && StringUtils.isNotEmpty(deadline2)) {
                                return deadline2.compareTo(deadline1);
                            }
                            return 1;
                        });
                    }
                });

                List<TPolicyApplicationDemonstrationDTO> app1 = groupingByApplicationStatusCollect.get(applicationStatus1);
                List<TPolicyApplicationDemonstrationDTO> app2 = groupingByApplicationStatusCollect.get(applicationStatus2);
                if (!CollectionUtils.isEmpty(app1)) {
                    result.addAll(app1);
                }
                if (!CollectionUtils.isEmpty(app2)) {
                    result.addAll(app2);
                }
                if (!StringUtils.isNotEmpty(applicationStatus)) {
                    result.addAll(applicationStatusNulls);
                }
            }
        }

        int sIndex = (page - 1) * size;
        List<PolicyApplicationDemonstration> resultByPageInfo = result.stream()
                .map(item -> {
                    PolicyApplicationDemonstration policyApplicationDemonstration = new PolicyApplicationDemonstration();
                    BeanUtils.copyProperties(item, policyApplicationDemonstration);
                    String startDate = item.getStartDate();
                    if (StringUtils.isNotEmpty(startDate)) {
                        String substring = startDate.substring(0, 10);
                        policyApplicationDemonstration.setStartDate(substring);
                    }
                    String deadline = item.getDeadline();
                    if (StringUtils.isNotEmpty(deadline)) {
                        String substring = deadline.substring(0, 10);
                        policyApplicationDemonstration.setDeadline(substring);
                    }
                    return policyApplicationDemonstration;
                })
                .skip(sIndex)
                .limit(size)
                .collect(Collectors.toList());

        List<String> competentDepartmentMainData = getSourceData("t_PolicyApplicationDemonstration.competentDepartment");
        List<String> applicationStatusMainData = getSourceData("t_PolicyApplicationDemonstration.applicationStatus");

        MenusRep menusRep = new MenusRep()
                .setCompetentDepartmentMainData(competentDepartmentMainData)
                .setApplicationStatusMainData(applicationStatusMainData)
                .setTotal(result.size())
                .setPolicyApplicationDemonstrations(resultByPageInfo);

        return new ResponseResult<>(CommonCode.SUCCESS, menusRep);
    }

    private List<TPolicyApplicationDemonstrationDTOPageInfoResponse> apps() {
        Double aDouble = appTotal();

        List<TPolicyApplicationDemonstrationDTOPageInfoResponse> apps = new ArrayList<>();

        if (aDouble != null) {
            int size = 3000;
            double v = aDouble / size;
            double ceil = Math.ceil(v);
            long round = Math.round(ceil);
            for (long i = 1; i <= round; i++) {
                List<TPolicyApplicationDemonstrationDTOPageInfoResponse> appsByPageInfo = appsByPageInfo(i + "", size + "");
                if (appsByPageInfo != null) {
                    apps.addAll(appsByPageInfo);
                }
            }
        }
        return apps;
    }

    private Double appTotal() {
        TPolicyApplicationDemonstrationDTOPageInfo pageInfo = new TPolicyApplicationDemonstrationDTOPageInfo();
        pageInfo.set$PageNum(1);
        pageInfo.set$PageSize(5);
        //pageInfo.setatsandboxDBId(ConstantExt._SAND_BOX_ID);
        DataResponsetPolicyApplicationDemonstrationDTOPageInfodata data = tpolicyapplicationdemonstrationApi.findPageInfotPolicyApplicationDemonstrationUsingPOST(pageInfo).getData();
        if (data != null) {
            String total = data.getTotal();
            if (StringUtils.isNotEmpty(total)) {
                return Double.parseDouble(total);
            }
        }
        return null;
    }

    private List<TPolicyApplicationDemonstrationDTOPageInfoResponse> appsByPageInfo(String page, String size) {
        TPolicyApplicationDemonstrationDTOPageInfo pageInfo = new TPolicyApplicationDemonstrationDTOPageInfo();
        pageInfo.set$PageNum(Integer.valueOf(page));
        pageInfo.set$PageSize(Integer.valueOf(size));
        //pageInfo.setatsandboxDBId(ConstantExt._SAND_BOX_ID);
        DataResponsetPolicyApplicationDemonstrationDTOPageInfodata data = tpolicyapplicationdemonstrationApi.findPageInfotPolicyApplicationDemonstrationUsingPOST(pageInfo).getData();
        if (data != null) {
            List<TPolicyApplicationDemonstrationDTOPageInfoResponse> dataList = data.getDataList();
            if (dataList != null && dataList.size() > 0) {
                return dataList.stream().peek(item -> {
                    String competentDepartment = item.getCompetentDepartment();
                    String applicationStatus = item.getApplicationStatus();

                    JSONObject competentDepartmentJson = JsonUtils.jsonStrToJson(competentDepartment);
                    JSONObject applicationStatusJson = JsonUtils.jsonStrToJson(applicationStatus);
                    if (competentDepartmentJson != null) {
                        item.setCompetentDepartment(competentDepartmentJson.getString("name"));
                    }
                    if (applicationStatusJson != null) {
                        item.setApplicationStatus(applicationStatusJson.getString("name"));
                    }
                }).collect(Collectors.toList());
            }
        }
        return null;
    }

    @Override
    public ResponseResult<List<LatestPolicy>> latestPolicyListByPageInfo(Integer page, Integer size) {
        TLatestPolicyDTOPageInfo pageInfo = new TLatestPolicyDTOPageInfo();
        pageInfo.set$PageNum(page);
        size = size < 5 ? 5 : size;
        pageInfo.set$PageSize(size);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("dateTime", "desc");
        pageInfo.set$SortField(jsonObject.toJSONString());
        //pageInfo.setatsandboxDBId(ConstantExt._SAND_BOX_ID);
        DataResponsetLatestPolicyDTOPageInfodata data = tlatestpolicyApi.findPageInfotLatestPolicyUsingPOST(pageInfo).getData();

        List<LatestPolicy> latestPolicys = new ArrayList<>();
        if (data != null) {
            List<TLatestPolicyDTOPageInfoResponse> dataList = data.getDataList();
            if (!CollectionUtils.isEmpty(dataList)) {
                latestPolicys = dataList.stream().map(item -> {
                    LatestPolicy latestPolicy = new LatestPolicy();
                    BeanUtils.copyProperties(item, latestPolicy);
                    return latestPolicy;
                }).collect(Collectors.toList());
            }
        }
        return new ResponseResult<>(CommonCode.SUCCESS, latestPolicys);
    }

    @Override
    public ResponseResult<Map<Object, Object>> mainDataList() {
        //行业主数据
        List<JSONObject> industryList = industryList();

        Map<Object, Object> resMap = Maps.newConcurrentMap();
        MainDataRep m1 = new MainDataRep("行业", industryList);

        resMap.put("industryList", m1);

        Map<Object, Object> fieldMapping = Maps.newConcurrentMap();
        fieldMapping.put("企业资质", "quality");
        fieldMapping.put("企业规模", "scale");
        fieldMapping.put("独立法人", "individual");
        fieldMapping.put("是否存在违法违规...", "whetherviolate");
        fieldMapping.put("市场占有率", "marketoccupancy");
        fieldMapping.put("是否建立制定并...", "wanshantixi");
        fieldMapping.put("是否同1所...", "xueyanhezuo");
        fieldMapping.put("是否有研发场地...", "changdishebei");
        fieldMapping.put("是否有良好的...", "tuanduifengkong");
        fieldMapping.put("是否有在建项目...", "underconstruction");
        fieldMapping.put("是否留学人员", "goabroad");
        fieldMapping.put("户籍", "census");
        fieldMapping.put("主持或...", "projects");
        fieldMapping.put("产品细分市场领域内排名", "marketRanking");

        CountDownLatch countDownLatch = new CountDownLatch(fieldMapping.size());
        ThreadPoolExecutor threadPoolExecutor = ApiInit.threadPoolExecutor();
        try {
            fieldMapping.forEach((k, v) -> {
                threadPoolExecutor.execute(() -> {
                    List<String> sourceData = getSourceData("t_AccurateMatching." + v);
                    MainDataRep mainData = new MainDataRep(k, sourceData);
                    resMap.put(v, mainData);
                    countDownLatch.countDown();
                });
            });
            countDownLatch.await();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            threadPoolExecutor.shutdown();
        }
        return new ResponseResult<>(CommonCode.SUCCESS, resMap);
    }

    private List<String> getSourceData(String pojoAndfield) {
        List<String> res = new ArrayList<>();

        String region = "cn-north-2";
        String timestamp = String.valueOf(System.currentTimeMillis() / 1000);
        String sign = DigestUtils.md5Hex(Finals.ACCESSKEYID + Finals.ACCESSKEYSECRET + timestamp);

        JSONObject body = new JSONObject();
        body.put("data", pojoAndfield);

        Unirest.setTimeouts(5000000, 5000000);
        try {
            HttpResponse<JsonNode> response = Unirest.post(Finals.MAINDATASURL)
                    .header("Content-Type", "application/json")
                    .header("accessKeyId", Finals.ACCESSKEYID)
                    .header("accessKeySecret", Finals.ACCESSKEYSECRET)
                    .header("region", region)
                    .header("timestamp", timestamp)
                    .header("sign", sign)
                    .body(body.toJSONString())
                    .asJson();
            if (HttpStatus.SC_OK == response.getStatus()) {
                org.json.JSONObject repBody = response.getBody().getObject();
                if (repBody != null) {
                    JSONArray data = repBody.getJSONArray("data");
                    if (data != null && data.length() > 0) {
                        data.forEach(item -> {
                            JSONObject itemJson = JsonUtils.objToJson(item);
                            if (itemJson != null) {
                                res.add(itemJson.getString("name"));
                            }
                        });
                    }
                }
            }
        } catch (UnirestException e) {
            e.printStackTrace();
        }
        return res;
    }

    private List<JSONObject> industryList() {
        Double total = industryListTotal();
        if (total != null) {
            int size = 3000;
            double v = total / size;
            double ceil = Math.ceil(v);
            List<TindustryDTOPageInfoResponse> industrys = new ArrayList<>();
            for (long i = 1; i <= Math.round(ceil); i++) {
                List<TindustryDTOPageInfoResponse> industrysByPage = industryListByPage(i + "", size + "");
                if (industrysByPage != null) {
                    industrys.addAll(industrysByPage);
                }
            }
            if (!CollectionUtils.isEmpty(industrys)) {
                return industrys.stream().map(item -> {
                    JSONObject jsonObject = new JSONObject();
                    jsonObject.put("id", item.getId());
                    jsonObject.put("name", item.getName());
                    return jsonObject;
                }).collect(Collectors.toList());
            }
        }
        return new ArrayList<>();
    }

    private Double industryListTotal() {
        TindustryDTOPageInfo pageInfo = new TindustryDTOPageInfo();
        pageInfo.set$PageNum(1);
        pageInfo.set$PageSize(5);
        //pageInfo.setatsandboxDBId(ConstantExt._SAND_BOX_ID);
        DataResponsetindustryDTOPageInfodata rep = tindustryApi.findPageInfotIndustryUsingPOST(pageInfo).getData();
        if (rep != null) {
            String total = rep.getTotal();
            if (StringUtils.isNotEmpty(total)) {
                return Double.parseDouble(total);
            }
        }
        return null;
    }

    private List<TindustryDTOPageInfoResponse> industryListByPage(String page, String size) {
        TindustryDTOPageInfo pageInfo = new TindustryDTOPageInfo();
        pageInfo.set$PageNum(Integer.valueOf(page));
        pageInfo.set$PageSize(Integer.valueOf(size));
        //pageInfo.setatsandboxDBId(ConstantExt._SAND_BOX_ID);
        DataResponsetindustryDTOPageInfodata rep = tindustryApi.findPageInfotIndustryUsingPOST(pageInfo).getData();
        if (rep != null) {
            List<TindustryDTOPageInfoResponse> dataList = rep.getDataList();
            if (!CollectionUtils.isEmpty(dataList)) {
                return dataList;
            }
        }
        return null;
    }

    private List<JSONObject> subDomainList() {
        Double total = subDomainTotal();
        if (total != null) {
            int size = 3000;
            double v = total / size;
            double ceil = Math.ceil(v);
            List<TsubDomainDTOPageInfoResponse> subDomains = new ArrayList<>();
            for (long i = 1; i <= Math.round(ceil); i++) {
                List<TsubDomainDTOPageInfoResponse> subDomainByPage = subDomainByPage(i + "", size + "");
                if (subDomainByPage != null) {
                    subDomains.addAll(subDomainByPage);
                }
            }
            if (!CollectionUtils.isEmpty(subDomains)) {
                return subDomains.stream().map(item -> {
                    JSONObject jsonObject = new JSONObject();
                    jsonObject.put("id", item.getId());
                    jsonObject.put("name", item.getName());
                    return jsonObject;
                }).collect(Collectors.toList());
            }
        }
        return new ArrayList<>();
    }

    private Double subDomainTotal() {
        TsubDomainDTOPageInfo pageInfo = new TsubDomainDTOPageInfo();
        pageInfo.set$PageNum(1);
        pageInfo.set$PageSize(5);
        //pageInfo.setatsandboxDBId(ConstantExt._SAND_BOX_ID);
        DataResponsetsubDomainDTOPageInfodata data = tsubdomainApi.findPageInfotSubDomainUsingPOST(pageInfo).getData();
        if (data != null) {
            String total = data.getTotal();
            if (StringUtils.isNotEmpty(total)) {
                return Double.parseDouble(total);
            }
        }
        return null;
    }

    private List<TsubDomainDTOPageInfoResponse> subDomainByPage(String page, String size) {
        TsubDomainDTOPageInfo pageInfo = new TsubDomainDTOPageInfo();
        pageInfo.set$PageNum(Integer.valueOf(page));
        pageInfo.set$PageSize(Integer.valueOf(size));
        //pageInfo.setatsandboxDBId(ConstantExt._SAND_BOX_ID);
        DataResponsetsubDomainDTOPageInfodata data = tsubdomainApi.findPageInfotSubDomainUsingPOST(pageInfo).getData();
        if (data != null) {
            List<TsubDomainDTOPageInfoResponse> dataList = data.getDataList();
            if (!CollectionUtils.isEmpty(dataList)) {
                return dataList;
            }
        }
        return null;
    }

    @Override
    public ResponseResult<List<JSONObject>> subDomainListByIndustryIds(List<String> industryIds) {
        List<TsubDomainDTOResponse> subDomainListAllByIndustry = new ArrayList<>();
        industryIds.forEach(item -> {
            List<TsubDomainDTOResponse> subDomainListByIndustry = subDomainListByIndustry(item);
            if (subDomainListByIndustry != null) {
                subDomainListAllByIndustry.addAll(subDomainListByIndustry);
            }
        });
        List<JSONObject> collect = new ArrayList<>();
        if (subDomainListAllByIndustry.size() > 0) {
            collect = subDomainListAllByIndustry.stream().map(item -> {
                JSONObject jsonObject = new JSONObject();
                jsonObject.put("id", item.getId());
                jsonObject.put("name", item.getName());
                return jsonObject;
            }).collect(Collectors.toList());
        }
        return new ResponseResult<>(CommonCode.SUCCESS, collect);
    }

    private List<TsubDomainDTOResponse> subDomainListByIndustry(String industry) {
        TsubDomainDTO query = new TsubDomainDTO();
        query.setIndustry(industry);
        //query.setatsandboxDBId(ConstantExt._SAND_BOX_ID);
        List<TsubDomainDTOResponse> data = tsubdomainApi.findtSubDomainUsingPOST(query).getData();
        if (!CollectionUtils.isEmpty(data)) {
            return data;
        }
        return null;
    }

    @Override
    public ResponseResult<Introduction> introduction() {
        Introduction introduction = null;

        List<TIntroductionDTOPageInfoResponse> introductionByPage = introductionByPage("1", "5");
        if (introductionByPage != null) {
            introduction = new Introduction();
            TIntroductionDTOPageInfoResponse introductionDto1 = introductionByPage.get(0);
            BeanUtils.copyProperties(introductionDto1, introduction);
        }
        return new ResponseResult<>(CommonCode.SUCCESS, introduction);
    }

    private List<TIntroductionDTOPageInfoResponse> introductionByPage(String page, String size) {
        TIntroductionDTOPageInfo pageInfo = new TIntroductionDTOPageInfo();
        pageInfo.set$PageNum(Integer.valueOf(page));
        pageInfo.set$PageSize(Integer.valueOf(size));
        //pageInfo.setatsandboxDBId(ConstantExt._SAND_BOX_ID);
        DataResponsetIntroductionDTOPageInfodata data = tintroductionApi.findPageInfotIntroductionUsingPOST(pageInfo).getData();
        if (data != null) {
            List<TIntroductionDTOPageInfoResponse> dataList = data.getDataList();
            if (!CollectionUtils.isEmpty(dataList)) {
                return dataList;
            }
        }
        return null;
    }

    @Override
    public ResponseResult<PolicyDataCenter> policyDataCenter() {
        PolicyDataCenter policyDataCenter = null;

        List<TPolicyDataCenterDTOPageInfoResponse> policyDataCenterByPage = policyDataCenterByPage("1", "5");
        if (policyDataCenterByPage != null) {
            policyDataCenter = new PolicyDataCenter();
            TPolicyDataCenterDTOPageInfoResponse policyDataCenterDto1 = policyDataCenterByPage.get(0);
            BeanUtils.copyProperties(policyDataCenterDto1, policyDataCenter);

            String policyDataCenterId = policyDataCenterDto1.getId();
            List<THorizontalAxisDTOResponse> horizontalAxisByPolicyDataCenter = horizontalAxisByPolicyDataCenter(policyDataCenterId);

            List<PolicyDataCenter.HorizontalAxis> collect = new ArrayList<>();

            if (horizontalAxisByPolicyDataCenter != null) {
                collect = horizontalAxisByPolicyDataCenter.stream().map(item -> {
                    PolicyDataCenter.HorizontalAxis horizontalAxis = new PolicyDataCenter.HorizontalAxis();
                    BeanUtils.copyProperties(item, horizontalAxis);
                    return horizontalAxis;
                }).collect(Collectors.toList());
            }
            policyDataCenter.setHorizontalAxes(collect);
        }
        return new ResponseResult<>(CommonCode.SUCCESS, policyDataCenter);
    }

    private List<TPolicyDataCenterDTOPageInfoResponse> policyDataCenterByPage(String page, String size) {
        TPolicyDataCenterDTOPageInfo pageInfo = new TPolicyDataCenterDTOPageInfo();
        pageInfo.set$PageNum(Integer.valueOf(page));
        pageInfo.set$PageSize(Integer.valueOf(size));
        //pageInfo.setatsandboxDBId(ConstantExt._SAND_BOX_ID);
        DataResponsetPolicyDataCenterDTOPageInfodata data = tpolicydatacenterApi.findPageInfotPolicyDataCenterUsingPOST(pageInfo).getData();
        if (data != null) {
            List<TPolicyDataCenterDTOPageInfoResponse> dataList = data.getDataList();
            if (!CollectionUtils.isEmpty(dataList)) {
                return dataList;
            }
        }
        return null;
    }

    private List<THorizontalAxisDTOResponse> horizontalAxisByPolicyDataCenter(Object policyDataCenter) {
        THorizontalAxisDTO query = new THorizontalAxisDTO();
        query.setPolicyDataCenter(policyDataCenter);
        //query.setatsandboxDBId(ConstantExt._SAND_BOX_ID);
        List<THorizontalAxisDTOResponse> data = thorizontalaxisApi.findtHorizontalAxisUsingPOST(query).getData();
        if (!CollectionUtils.isEmpty(data)) {
            return data;
        }
        return null;
    }

}
